package com.gzy.cbrsystem.insomnia.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
	private static final long serialVersionUID = 1030294046920869257L;
	private String username;
	private String password;

	public String execute() throws Exception {
		
		if (isInvalid(getUsername()))
			return INPUT;

		if (isInvalid(getPassword()))
			return INPUT;

		if ((getUsername().equals("mm") || getUsername().equals("aumy"))
				&& getPassword().equals("111")) {
			ActionContext.getContext().getSession().put("username", getUsername());
			ActionContext.getContext().getSession().put("password", getPassword());
			System.out.println(getUsername() + "----" + getPassword());
			return SUCCESS;
		} else {
			System.out.println(getUsername() + "----" + getPassword());
			return ERROR;
		}
		
	}

	private boolean isInvalid(String value) {
		return (value == null || value.length() == 0);
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
}
